<template>
	<div class="pay-order-check">
		<el-breadcrumb separator-class="el-icon-arrow-right" style="margin-bottom:15px;">
			<el-breadcrumb-item v-if="source==='search'":to="{ path: '/settlesearch' }">支付清单查询</el-breadcrumb-item>
			<el-breadcrumb-item v-else :to="{ path: '/tobepaidlist' }">待支付清单</el-breadcrumb-item>
			<el-breadcrumb-item>查看流程</el-breadcrumb-item>
		</el-breadcrumb>
		<div class="top" style="text-align: right;">
			<el-button type="text" size="small" @click="submitCheck1" :disabled="payInventoryCode=='' ? false : true ">提交审批</el-button>
			<el-button type="text" size="small" @click="cancel" :disabled="payInventoryCode=='' ? false : true ">取消</el-button>
			<el-button type="text" size="small" disabled>撤回</el-button>
			<el-button type="text" size="small" @click="lookProgress" :disabled="payInventoryCode=='' ? true : false ">查看流程痕迹</el-button>
			<!-- <el-button type="text" size="small" @click="lookFile" :disabled="payInventoryCode=='' ? true : false ">附件</el-button> -->
			<el-button size="small" @click="cancel">关闭</el-button>
		</div>
		<h2 class="title">{{initType(orderType)}}费用支付清单审批</h2>
		<div class="table-title">
			<p>服务中心名称：好生活</p>
			<p>支付清单编号：{{payInventoryCode}}</p>
			<p>制表日期：{{createTime}}</p>
		</div>
		<el-table :data="tableData" border>
			<el-table-column type="index" label="序号" width="80" align="center"></el-table-column>
			<el-table-column  prop="projectName" label="项目" align="center"></el-table-column>
			<el-table-column  prop="code" label="付款单号" align="center"></el-table-column>
			<el-table-column  prop="summary" label="摘要（付款事项）" align="center"></el-table-column>
			<el-table-column  prop="recName" label="收款人/单位名称" align="center"></el-table-column>
			<el-table-column  prop="provinceCity" label="开卡省份-城市" align="center"></el-table-column>
			<el-table-column  prop="recSubBankName" label="开户名称" align="center"></el-table-column>
			<el-table-column  prop="recAccNo" label="开户账号" align="center"></el-table-column>
			<el-table-column  prop="amount" label="应付款金额（元）" align="center" :formatter="toFixedFn"></el-table-column>
			<el-table-column  prop="payAmount" label="实际付款金额（元）" align="center" :formatter="toFixedFn"></el-table-column>
		</el-table>
		<div style="margin-top:15px;font-size:15px;">
			合计：{{this.toFixedFn1(total)}}元
		</div>
		<div class="table-title">
			<p>好生活运营总（签字）：{{oneVerifyName}}</p>
			<p>好生活财务总（签字）：{{twoVerifyName}}</p>
			<p>制表人：{{userName}}</p>
		</div>
		<el-dialog title="附件信息" :visible.sync="dialogVisible" >
			<el-table :data="Datatable" border>
				<el-table-column type="index" label="序号" width="80" align="center"></el-table-column>
				<el-table-column  prop="type" label="文件信息" align="center" :formatter="initTypees"></el-table-column>
				<el-table-column  prop="uploadName" label="创建人" align="center"></el-table-column>
				<el-table-column  prop="uploadTime" label="上传时间" align="center" :formatter="initTime"></el-table-column>
			</el-table>
		</el-dialog>
	</div>
</template>

<script>
	import utils from "../../../../common/utils"
	export default {
		data(){
			return {
				total:"",
				dialogVisible:false,
				Datatable:[],
				source:this.$route.query.source,
				tableData:[],
				type:this.$route.query.type,
				ids:this.$route.query.ids,
				payInventoryCode:this.$route.query.code || "",
				createTime:"",
				orderType:"",
				oneVerifyName:"",
				twoVerifyName:"",
				userName:"",
				hoststring:"",
				workItemId:"",
				instanceId:"",
				mobile:""
			}
		},
		methods:{
			initTime(row, column, cellValue, index){
				return utils.getTimeString(cellValue)
			},
			initTypees(row, column, cellValue, index){
				if(cellValue==1){return "发票"}
				if(cellValue==2){return "渠道合作通知函"}
				if(cellValue==3){return "佣金确认表及其他"}
				if(cellValue==4){return "认购书"}
				if(cellValue==5){return "身份证复印件"}
				if(cellValue==6){return "银行账户信息复印件"}
				if(cellValue==7){return "退款凭证"}
				if(cellValue==8){return "支付清单"}
				if(cellValue==9){return "付款审批意见"}
			},
			lookFile(){
				this.$axios.post("kingdee/payList/payInventoryEnclosure",{payInventoryCode:this.payInventoryCode}).then((res)=>{
					this.dialogVisible=true;
					this.Datatable=res;
					console.log(res);
				}).catch((error)=>{
					console.log(error)
				})
			},
			checkhost(){
	            let hosname=document.domain;
	            if(hosname=="localhost"){
	                this.hoststring="http://th3bpm.lifeat.cn:45787"
	            }
	            if(hosname=="ntcms.lifeat.cn"){
	                this.hoststring="http://th3bpm.lifeat.cn:45787"
	            }
	            if(hosname=="ncms.lifeat.cn"){
	                this.hoststring="http://h3bpm.lifeat.cn"
	            }
	            if(hosname=="nhcms.lifeat.cn"){
	                this.hoststring="http://hh3bpm.lifeat.cn:45788"
	            }
	        },
			lookProgress(){
				var url = this.hoststring+"/Portal/#/platform/login?mobile=" + this.mobile + "&workItemId=" +  this.workItemId + "&instanceId=" + this.instanceId;
				window.open(url);
			},
			loadData1(){
				this.$axios.post("/kingdee/payList/preview",this.ids).then((res)=>{
					console.log(res);
					this.tableData=res.list;
					this.createTime=res.createTime;
					this.orderType=res.type;
					this.userName=res.userName;
					this.oneVerifyName=res.oneVerifyName;
					this.twoVerifyName=res.twoVerifyName;
					this.total=res.totalAmount;
				}).catch((error)=>{
					console.log(error)
				})
			},
			loadData2(){
				this.$axios.post("/kingdee/payList/payInventoryDetails",{payInventoryCode:this.payInventoryCode}).then((res)=>{
					console.log(res);
					this.tableData=res.list;
					this.createTime=res.createTime;
					this.orderType=res.type;
					this.userName=res.userName;
					this.oneVerifyName=res.oneVerifyName;
					this.twoVerifyName=res.twoVerifyName;
					this.workItemId=res.workItemId;
					this.instanceId=res.instanceId;
					this.total=res.totalAmount;
				}).catch((error)=>{
					console.log(error)
				})
			},
			toFixedFn(row, column, cellValue, index) { //保留两位小数并且千分位展示
				if (cellValue != undefined && cellValue != null && cellValue.toString() != "") {
					let tempValue = parseFloat(cellValue)
					return tempValue.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
				}
		    },
		    toFixedFn1(cellValue) { //保留两位小数并且千分位展示
				if (cellValue != undefined && cellValue != null && cellValue.toString() != "") {
					let tempValue = parseFloat(cellValue)
					return tempValue.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
				}
		    },
		    initType(params){
		    	if(params==1){
		    		return "结佣"
		    	}
		    	if(params==2){
		    		return "退款"
		    	}
		    },
		    submitCheck1(){
		    	this.$axios.post("/kingdee/payList/addPayInventoryAndSubmitVerify",this.ids).then((res)=>{
					this.$message({
						showClose: true,
						message: '成功提交到H3审批',
						type: 'success',
						onClose:()=>{
							this.$router.push({
								path:"/tobepaidlist"
							})
						}
					});
				}).catch((error)=>{
					console.log(error);
				})
		    },
		    cancel(){
		    	if(this.type=="view" || this.source=="list"){
		    		this.$router.push({
						path:"/tobepaidlist"
					})
		    	}
		    	if(this.source=="search"){
		    		this.$router.push({
						path:"/settlesearch"
					})
		    	}
		    }
		},
		mounted(){
			if(this.type=="view"){
				this.loadData1();
			}
			if(this.type=="look"){
				this.loadData2();
			}
			this.mobile=JSON.parse(sessionStorage.getItem("cmsUser")).mobile;
			this.checkhost();
		}
	}
</script>


<style lang="stylus" scope>
	.pay-order-check{
		.title{
			color:#0072A4;
			text-align: center;
		}
		.table-title{
			font-size:14px;
			p{
				display: inline-block;
			}
			p:nth-of-type(2){
				margin-left: 400px;
				margin-right: 400px;
			}
		}
	}
</style>
